//
//  defines.h
//  yingpa
//
//  Created by 谭亚明 on 2020/3/22.
//  Copyright © 2020 it. All rights reserved.
//

#ifndef defines_h
#define defines_h

#define weak(A) __weak typeof(A) w_##A = A;
#define strong(A) __strong typeof(A) w_##A = A;

#ifndef weakify
#if DEBUG
#if __has_feature(objc_arc)
#define weakify(object) autoreleasepool{} __weak __typeof__(object) weak##_##object = object;
#else
#define weakify(object) autoreleasepool{} __block __typeof__(object) block##_##object = object;
#endif
#else
#if __has_feature(objc_arc)
#define weakify(object) try{} @finally{} {} __weak __typeof__(object) weak##_##object = object;
#else
#define weakify(object) try{} @finally{} {} __block __typeof__(object) block##_##object = object;
#endif
#endif
#endif

#ifndef strongify
#if DEBUG
#if __has_feature(objc_arc)
#define strongify(object) autoreleasepool{} __typeof__(object) object = weak##_##object;
#else
#define strongify(object) autoreleasepool{} __typeof__(object) object = block##_##object;
#endif
#else
#if __has_feature(objc_arc)
#define strongify(object) try{} @finally{} __typeof__(object) object = weak##_##object;
#else
#define strongify(object) try{} @finally{} __typeof__(object) object = block##_##object;
#endif
#endif
#endif

//! 输出，断言 仅在debug模式下有效
#ifdef DEBUG
#define YPLog(format,...) NSLog(format,##__VA_ARGS__)
#define NSLog(FORMAT, ...) fprintf(stderr,"%s:%d\t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#define YPAssert(condition, desc, ...) NSAssert(condition,desc,##__VA_ARGS__)
#else
#define YPLog(format,...)
#define NSLog(FORMAT, ...)
#define YPAssert(condition, desc, ...)
#endif

#endif /* defines_h */
